// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import App from './App'
import router from './router'

Vue.config.productionTip = false
import axios from 'axios'

axios.interceptors.request.use(config=>{
    var token = localStorage.getItem('token')
    if(token){
        config.headers['token'] = token   
    } return config
})






Vue.prototype.axios = axios;
axios.defaults.baseURL = "http://127.0.0.1:8000/"


import ElementUI from 'element-ui';
import 'element-ui/lib/theme-chalk/index.css';





Vue.use(ElementUI);
router.beforeEach((to,from,next)=>{
    // 定义白名单
    var white = ['/login','/deng','/xou']
    // 判断是否在白名单中，如果在继续执行next()
    if (white.indexOf(to.path)>=0){
        next()
    }else{
        // 如果不在判断token是否 存在已登录
        var token = localStorage.getItem('token')
        if(token){
            var mpstatus = localStorage.getItem('mpstatus')
            if (mpstatus == 1){
                window.location.href = 'http://localhost:8080/#/xou'

            } else{
                var pomitionlist = JSON.parse(localStorage.getItem('pomitionlist'))
                if (pomitionlist.indexOf(to.path)>=0){
                    next()

                }else{
                    alert('没有权限访问')
                    return false;
                }
            }
        }else{
            alert('无权访问')
            window.location.href = 'http://localhost:8080/#/deng'
            return
        }
    }
})

/* eslint-disable no-new */
new Vue({
    el: '#app',
    router,
    components: { App },
    template: '<App/>'
})